// 标题栏预加载脚本
const { contextBridge, ipcRenderer } = require('electron');

// 记录预加载脚本已执行
console.log('标题栏预加载脚本开始执行');

// 暴露 API 给标题栏
contextBridge.exposeInMainWorld('titlebarAPI', {
  clearCache: () => {
    console.log('预加载脚本: 调用clearCache');
    return ipcRenderer.invoke('clear-cache');
  },
  minimizeWindow: () => {
    console.log('预加载脚本: 调用minimizeWindow');
    ipcRenderer.send('minimize-window');
  },
  maximizeWindow: () => {
    console.log('预加载脚本: 调用maximizeWindow');
    ipcRenderer.send('maximize-window');
  },
  closeWindow: () => {
    console.log('预加载脚本: 调用closeWindow');
    ipcRenderer.send('close-window');
  }
});

// 监听主进程的消息
ipcRenderer.on('console-log', (event, message) => {
  console.log(`来自主进程的消息: ${message}`);
});

console.log('标题栏预加载脚本执行完毕'); 